<template>
	<view>

		<view class="logo flex align-center justify-center">
			<image class="logo-img" src="/static/logo.png"></image>
		</view>

		<view class="login flex align-center justify-center">
			<view class="login-btn-two textCenter" @click="getInfo">点击获取用户信息</view>
		</view>


	</view>

</template>

<script>
	import {
		ouathToken
	} from '@/api/account.js'
	export default {
		data() {
			return {
				code:''

			}
		},
		onLoad() {
			
		},
		onShow() {


		},

		methods: {

			// 获取用户资料获取手机号码
			getInfo() {
				let that = this;
				
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						console.log(loginRes, 'login获取相应code');
						that.code = loginRes.code;
				
					}
				});
				
				console.log('获取用户信息')
				uni.getUserProfile({
					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (res) => {
						console.log(res, '获取用户资料')
						let data = res;

						ouathToken({
							"code":that.code,
							"iv":data.iv,
							"grant_type":'wechat_applet',
							"encryptedData":data.encryptedData
						}).then(res => {
							console.log(res, '获取相应的数据')

							uni.setStorageSync('token', res.access_token);

						})
					},
					fail:(res)=>{
						console.log(res,'拒绝提供相应信息')
						
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 1500)
						
					}
				})


			},



		}
	}
</script>

<style lang="scss">
	// 头像
	.logo {
		width: 750rpx;
		height: 800rpx;

		.logo-img {
			width: 360rpx;
			height: 360rpx;
		}

	}

	.login {
		width: 750rpx;
		height: 96rpx;

		.login-btn {
			width: 580rpx;
			height: 96rpx;
			background: #DC2D20;
			border-radius: 48rpx;
			font-size: 32rpx;
			font-family: PingFangSC-Bold, PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			line-height: 96rpx;
		}

		.login-btn-two {
			width: 580rpx;
			height: 96rpx;
			background: #DC2D20;
			border-radius: 48rpx;
			font-size: 32rpx;
			font-family: PingFangSC-Bold, PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			line-height: 96rpx;
		}
	}



	.getuserinfo {
		width: 750rpx;
		height: 100rpx;
		line-height: 100rpx;
		color: white;
		font-size: 28rpx;
		text-align: center;
		background-color: blue;
		margin-top: 400rpx;
	}

	.useinfo {
		width: 100%;
		height: 100rpx;
		background-color: blue;
		color: white;
		text-align: center;
		line-height: 100rpx;
		margin-top: 20rpx;
	}

	.text {
		width: 750rpx;
		/* height: 300rpx; */
		word-wrap: break-word;
		word-break: normal;
		padding: 28rpx;
	}

	.text2 {
		width: 750rpx;
		/* height: 1000rpx; */
		word-wrap: break-word;
		word-break: normal;
		padding: 28rpx;
	}

	.copy {
		display: inline-block;
		width: 200rpx;
		height: 38rpx;
		line-height: 38rpx;
		border-radius: 36rpx;
		text-align: center;
		background-color: #ffaa7f;
		font-size: 26rpx;
		font-weight: bold;
		color: white;
	}
</style>
